<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      padding: 0;
      margin: 0;
    }
    li {
      list-style: none;
    }
    .container {
      width: 600px;
      height: 400px;
      border: 10px solid black;
      margin: 0 auto;
      display: flex;
      flex-direction: column;
    }
    ul {
      height: 80px;
      border: 1px solid red;
      display: flex;
      /* flex-direction: column; */
    }
    ul > li {
      flex: 1;
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 60px;
      cursor: pointer;
    }
    ul > li.active {
      background-color: palevioletred;
    }


    ol {
      flex: 1;
      position: relative;
    }
    ol > li {
      height: 100%;
      background: purple;
      font-size: 100px;
      font-weight: bold;
      /* display: flex; */
      justify-content: center;
      align-items: center;
      position: absolute;
      top: 0;
      width: 100%;
      display: none;
    }
    ol > li.active {
      display: flex;
    }


  </style>
</head>
<body>
  <div class="container">
    <!-- 表示 header -->
    <ul>
      <li class="active">1</li>
      <li>2</li>
      <li>3</li>
    </ul>

    <!-- 表示 body -->
    <ol>
      <li class="active">one</li>
      <li>two</li>
      <li>three</li>
    </ol>
  </div>
</body>
</html>
<script>
const ulLis = document.querySelectorAll('ul > li');
const olLis = document.querySelectorAll('ol > li');

// 1. 将 header ul 的 li ，单选

ulLis.forEach((ulLi, index) => {
  ulLi.addEventListener('click', e => {
    // 关注 header
    ulLis.forEach(li => li.classList.remove('active')); // 清除掉 所有的 li 的 class
    ulLi.classList.add('active');


    // 关注1）body     2)header与body的关联（通过index）
    // 点击 header 让 对应 的  body 的 li 标签，设为 class = 'active'
      // 思路：通过 index 将 header 和 body 进行关联
    olLis.forEach(olLi => olLi.classList.remove('active'));
    olLis[index].classList.add('active');
  })
})

</script>